load mgdata.dat
a = mgdata;
time = a(:, 1);
x_t = a(:, 2);
% plot(time, x_t);
% xlabel('Time (sec)','fontsize',10); ylabel('x(t)','fontsize',10);
% title('Mackey-Glass Chaotic Time Series','fontsize',10);

trn_data = zeros(500, 5);
chk_data = zeros(500, 5);

% prepare training data
trn_data(:, 1) = x_t(101:600);
trn_data(:, 2) = x_t(107:606);
trn_data(:, 3) = x_t(113:612);
trn_data(:, 4) = x_t(119:618);
trn_data(:, 5) = x_t(125:624);
save chaoTS.mat trn_data
save chaoTS.dat -ascii trn_data

% prepare checking data
chk_data(:, 1) = x_t(601:1100);
chk_data(:, 2) = x_t(607:1106);
chk_data(:, 3) = x_t(613:1112);
chk_data(:, 4) = x_t(619:1118);
chk_data(:, 5) = x_t(625:1124);

index = 119:1118; % ts starts with t = 0
plot(time(index), x_t(index));
xlabel('Time (sec)','fontsize',10); ylabel('x(t)','fontsize',10);
title('Mackey-Glass Chaotic Time Series','fontsize',10);

fismat = genfis(trn_data(:,1:end-1),trn_data(:,end), ...
    genfisOptions('GridPartition'));

% The initial MFs for training are shown in the plots.
for input_index=1:4
    subplot(2,2,input_index)
    [x,y]=plotmf(fismat,'input',input_index);
    %plotmf(fismat,'input',input_index);
    plot(x,y)
    axis([-inf inf 0 1.2]);
    xlabel(['Input ' int2str(input_index)],'fontsize',10);
end

